package com.example.gc.webredisgc.controller;

import com.allqj.qjf.multi.datasource.utils.TenantContextHolder;
import com.example.gc.webredisgc.dao.MisSaas;
import com.example.gc.webredisgc.dao.MisSaasDao;
import com.example.gc.webredisgc.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

/**
 * @author sjw
 * @className HomeController
 * @date 2021/9/19 10:39
 * @description: TODO
 */
@RestController
public class HomeController {

    @Autowired
    private MisSaasDao misSaasDao;

    @Autowired
    private HomeService homeService;

    @GetMapping("/hello/{name}")
    public Integer hello(@PathVariable String name) throws SQLException {
        MisSaas misSaa = new MisSaas();
        misSaa.setName(name);
        misSaasDao.save(misSaa);
        return TenantContextHolder.getTenantContext();
    }

    @GetMapping("/update/{name}")
    public Boolean update(@PathVariable String name) throws InterruptedException {

        return homeService.update(name);
    }


    @GetMapping("/es/{name}")
    public String es(@PathVariable String name) throws InterruptedException {

        return homeService.es(name);
    }


    @GetMapping("/async")
    public String async() throws InterruptedException {
        System.out.println("main----:" + TenantContextHolder.getTenantContext());
        homeService.async();
        return "async";
    }
}
